package com.icow.wms.basic.controller;

import com.icow.common.annotation.Log;
import com.icow.common.core.controller.BaseController;
import com.icow.common.core.domain.AjaxResult;
import com.icow.common.core.page.TableDataInfo;
import com.icow.common.enums.BusinessType;
import com.icow.common.utils.poi.ExcelUtil;
import com.icow.wms.basic.domain.LocationDomain;
import com.icow.wms.basic.domain.ProductDomain;
import com.icow.wms.basic.service.ILocationDomainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * LocationController
 *
 * @author ly
 * @date 2021-02-08
 */

@RestController
@RequestMapping("/wms.basic/location")
public class LocationDomainController extends BaseController {

    @Autowired
    private ILocationDomainService locationDomainService;

    /**
     * 查询Location列表
     */
    @GetMapping("/list")
    public TableDataInfo list(LocationDomain locationDomain){
        startPage();
        List<LocationDomain> list = locationDomainService.selectLocationDomainList(locationDomain);
        return getDataTable(list);
    }

    /**
     * 导出Location列表
     */
    @Log(title = "location", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LocationDomain locationDomain)
    {
        List<LocationDomain> list = locationDomainService.selectLocationDomainList(locationDomain);
        ExcelUtil<LocationDomain> util = new ExcelUtil<LocationDomain>(LocationDomain.class);
        return util.exportExcel(list, "Location");
    }

    /**
     * 获取Location详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(locationDomainService.selectLocationDomainById(id));
    }

    /**
     * 新增Location
     */
    @Log(title = "location", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LocationDomain locationDomain)
    {
        return toAjax(locationDomainService.insertLocationDomain(locationDomain));
    }

    /**
     * 修改Location
     */
    @Log(title = "location", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LocationDomain locationDomain)
    {
        return toAjax(locationDomainService.updateLocationDomain(locationDomain));
    }

    /**
     * 删除Location
     */
    @Log(title = "location", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(locationDomainService.deleteLocationDomainByIds(ids));
    }
}
